import sys
import os
from flask import jsonify

# 把common文件夹添加到搜索路径
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, os.path.join(BASE_DIR, 'common'))


# 导入创建flask app的工厂函数create_app
from . import create_app
# 导入默认配置类
from settings.default import DefaultConfig


# 创建flask 对象
app = create_app(DefaultConfig, enable_config_file=True)


@app.route('/')
def route_map():
    """
    主视图，返回所有视图网址
    """
    rules_iterator = app.url_map.iter_rules()
    return jsonify({rule.endpoint: rule.rule for rule in rules_iterator if rule.endpoint not in ('route_map', 'static')})
